//package com.zz.study.sharding.controller;
//
//import cn.hutool.core.lang.Snowflake;
//import cn.hutool.core.util.IdUtil;
//import com.zz.study.sharding.entity.Customer;
//import com.zz.study.sharding.entity.CustomerOrder;
//import com.zz.study.sharding.mappers.CustomerMapper;
//import com.zz.study.sharding.mappers.CustomerOrderItemMapper;
//import com.zz.study.sharding.mappers.CustomerOrderMapper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Random;
//
///**
// * @author zz
// * @version 1.0.0 2022-07-17
// */
//@RestController
//public class CustomerOrderController {
//
//    @Autowired
//    private CustomerMapper customerMapper;
//
//    @Resource
//    private CustomerOrderMapper customerOrderMapper;
//    @Resource
//    private CustomerOrderItemMapper customerOrderItemMapper;
//
//    @GetMapping("/createOrder")
//    public List<CustomerOrder> createOrder(@RequestParam(value = "size", defaultValue = "1") Integer size) {
//        List<CustomerOrder> customerOrders = new ArrayList<>(size);
//        List<Long > customIdList = new ArrayList<>();
//        List<Customer> customerList = customerMapper.findCustomerPage(0,10,null);
//        customerList.forEach(item->customIdList.add(item.getId()));
//
//        for (int i = 0; i < size; i++) {
//            Snowflake snowflake = IdUtil.getSnowflake(1, 1);
//            Long customerId = customIdList.get(new Random().nextInt(2));
//            long sallerId = snowflake.nextId();
//            Long orderId = new Long(snowflake.nextId());
//            String productName = "商品-" + new Random().nextInt(100);
//            customerOrderMapper.createOrder(snowflake.nextId(),orderId, customerId, sallerId, productName);
//            customerOrderItemMapper.createOrderItem(snowflake.nextId(),orderId, customerId, "商品描述-" + new Random().nextInt(100));
//            CustomerOrder order = new CustomerOrder();
//            order.setCustomerId(customerId);
//            order.setSallerId(sallerId);
//            order.setOrderId(orderId);
//            order.setProductName(productName);
//            customerOrders.add(order);
//        }
//        return customerOrders;
//    }
//
//    @GetMapping("findOrder")
//    public CustomerOrder findOrder(@RequestParam("orderId") BigDecimal orderId) {
//        return customerOrderMapper.findOrder(orderId);
//    }
//
//    @GetMapping("findCustomerOrders")
//    public List<CustomerOrder> findCustomerOrders(@RequestParam("customerId") Long customerId) {
//        return customerOrderMapper.findCustomerOrders(customerId);
//    }
//}
